package powerBusiness;

import com.alibaba.fastjson.JSONObject;
import easyDAO.SqlDispatch;
import impl.TestServerBusinessImpl;
import models.GetRequestInputStream;
import models.MyConfig;
import models.ReturnJson;
import models.SqlReturnModel;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by yangxianming on 2021/3/30.
 */
public class SetUserInfo implements TestServerBusinessImpl {
    @Override
    public String doIt(HttpServletRequest request, MyConfig myConfig) {
        ReturnJson returnJson = new ReturnJson();
        JSONObject requestInfo = GetRequestInputStream.getJson(request);

        System.out.println(requestInfo.get("powerPage"));
        System.out.println(requestInfo.get("userName"));

        String set = " SET power = '"+requestInfo.get("powerPage")+"' ";
        String where = " WHERE username='"+requestInfo.get("userName")+"' ";

        String sql1 = "UPDATE `user` " + set + where;
        SqlDispatch sqlDispatch = new SqlDispatch(myConfig);
        SqlReturnModel srm = sqlDispatch.update(sql1);
        if (srm.getIsSuccess()){
            returnJson.setResult("保存成功");
        }else {
            returnJson.setResult(0, null, srm.getFailingReason());
        }

        return returnJson.toString();
    }
}
